<template>
  <el-cascader size="mini" :options="treeData" :props="props" separator="-" :value="value" @change="changeValue" />
</template>

<script>
import { getDepartment } from '@/api/department'
import { transtoTreeData } from '@/utils/index'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      treeData: [],
      props: {
        label: 'name', // 要显示的值
        value: 'id'// 存储的值
      }
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      this.treeData = transtoTreeData(await getDepartment(), 0)
    },
    changeValue(list) {
      if (list.length > 0) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style>

</style>
